@extends('Admin.layouts.common')

@section('head')
<script>
    if(top.location != location){
        top.location.reload(true);
    }
</script>
@endsection

@section('content')
    <div class="login_container">
        <h2>{{env('APP_NAME')}}管理后台</h2>
        <form method="POST" id="admin_login_form">
            {{ csrf_field() }}
            <div class="form-group required">
                <input class="form-control" type="text" name="name" placeholder="账号">
            </div>
            <div class="form-group required">
                <input class="form-control" type="password" name="passwd" placeholder="密码">
            </div>
            <div class="form-group clearfix">
                <input id="captcha" name="captcha" type="text" maxlength="4" class="form-control" placeholder="验证码" autocomplete="off">
                <a href="javascript:void(0);" class="form-get-code">
                    <img src="/Auth/captcha?t={{ time() }}" alt="captcha" id="captchapng" onclick="refresh_captcha(this);" width="100" height="36">
                </a>
            </div>
            <div class="form-group">
                <button class="btn btn-primary btn-block" type="submit">登录</button>
            </div>
            <p class="form-group-static">Copyright © Cloud</p>
        </form>
    </div>
@endsection

@section('foot')
    <script>
        $.ajaxSetup({
            headers: {
            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
            }
        })
        
        $('#admin_login_form').submit(function (e) {
            e.preventDefault();
            btn_form($(this).find('button[type=submit]'));
            var form = $(this).serialize();
            $.ajax({
                type: 'post',
                data: form,
                dataType: 'json',
                complete: function () {
                    btn_form($('#admin_login_form button[type=submit]'));
                },
                success: function (d) {
                    if(d.status){
                        post(2, d.info);
                        window.location.href = '/';
                    }else{
                        post(3, d.info);
                    }
                },
                error: function (e) {
                    post(3, e.status + ': ' + e.statusText);
                }
            });
        });

    function refresh_captcha(obj){
        $(obj).attr('src',"/Auth/captcha?t="+Math.ceil(Math.random()*1000));
    }
    </script>
    <style>
    body{padding:0;margin:0;color:#333;}
    .login_container{min-width:320px;max-width:450px;width:30%;margin:0 auto;margin-top:150px;padding:15px;border-radius:5px;background:rgba(255, 255, 255, .75);}
    .login_container .form-control{height:36px !important;}
    .login_container h2{font-size:16px;text-align:center;margin-top:5px;margin-bottom:20px;}
    .login_container p{margin:0;text-align:center;}
    .login_container #captcha{float:left;width:calc(100% - 100px);border-radius:4px 0 0 4px;}
    .login_container #captchapng{float:left;border-radius: 0 4px 4px 0;border-left:none;}
    </style>
@endsection